/**
 * 对象数组分组排序
 * @param {*} groupType 
 * @param {*} groupAttr 
 * @param {*} groupVal 
 * @param {*} sortType 
 */
function objectArrayGroupBySort(groupType, groupAttr, groupVal, sortType = "DESC") {
  const sortTag = 'UUSORTKEY-GROUPBY-SORT-FIELD';

  return (a, b) => {
    if (groupType === 'string') {
      a[sortTag] = a[groupAttr] === groupVal ? 2 : 1;
      b[sortTag] = b[groupAttr] === groupVal ? 2 : 1;
    } else if (groupType === 'array') {
      a[sortTag] = !a[groupAttr] ? 2 : 1;
      b[sortTag] = !b[groupAttr] ? 2 : 1;
    } else {
      a[sortTag] = b[sortTag] = 2;
    }

    return sortType.toUpperCase() === "DESC" ? a[sortTag] - b[sortTag] : b[sortTag] - a[sortTag]
  }
}

export {
  objectArrayGroupBySort
}